Skip to content

fix(codegen-deno): don't re-declare preamble Option/Result constructors#606

Merged
hyperpolymath merged 1 commit into
mainfrom
claude/fix-deno-dup-constructors
Jun 20, 2026
Merged

fix(codegen-deno): don't re-declare preamble Option/Result constructors#606
hyperpolymath merged 1 commit into
mainfrom
claude/fix-deno-dup-constructors

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Deno-ESM: stop re-declaring the preamble's Option/Result constructors

The locally-declared sibling of the duplicate-constructor bug fixed in #604.

Bug

The Deno-ESM runtime preamble always declares Some/None/Ok/Err. gen_type_decl also emits them for any program that declares type Option/type Result — including stdlib/prelude.affine — so the emitted module crashes under node:

$ affinescript compile --deno-esm -o prelude.deno.js stdlib/prelude.affine
$ node prelude.deno.js
SyntaxError: Identifier 'Some' has already been declared

It stayed latent because the #136 AOT smoke only checks the emitted module is non-empty — it never runs it.

Fix

Skip the variants the preamble already provides (Some/None/Ok/Err) when lowering a TyEnum in codegen_deno.ml. User-defined enums are unaffected.

Verified

stdlib/prelude.affine -> deno : `const Some` ×1, runs under node ✅ (was ×2, crashed)
user enum (Color=Red|Green|Blue): still emitted, runs ✅
tools/run_codegen_deno_tests.sh : all harnesses pass under node ✅
dune test : 459 green (+1 new regression test)

New test Deno-ESM no duplicate Option/Result constructor asserts const Some is declared exactly once — the run-under-node guard the AOT smoke lacked.

Scope / follow-ups

🤖 Generated with Claude Code

https://claude.ai/code/session_01Lz7pRcec2Z3tVtaAhvB3M8


Generated by Claude Code

The Deno-ESM runtime preamble already declares Some/None/Ok/Err. gen_type_decl
re-emitted them for any program that DECLARES `type Option`/`type Result`
(e.g. stdlib/prelude.affine), so the emitted module crashed under node with
`SyntaxError: Identifier 'Some' has already been declared`. The #136 AOT smoke
never caught it — it only checks the emitted module is non-empty, never runs it.

Skip the variants the preamble already provides (Some/None/Ok/Err) when
lowering a TyEnum; user-defined enums are unaffected. Add a regression test
asserting `const Some` is declared exactly once.

This is the locally-declared sibling of the imported-constructor duplication
fixed in #604; together they close the duplicate-constructor class on the
Deno-ESM backend.

Verified: stdlib/prelude.affine now runs under node; dune test 459 green;
tools/run_codegen_deno_tests.sh all harnesses pass under node. The JS and C
backends share the same latent preamble/declaration duplication (not executed
in CI); tracked separately.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lz7pRcec2Z3tVtaAhvB3M8
@github-actions

Copy link
Copy Markdown

🔍 Hypatia Security Scan

Findings: 43 issues detected

Severity Count
🔴 Critical 2
🟠 High 25
🟡 Medium 16

⚠️ Action Required: Critical security issues found!

View findings
[
  {
    "reason": "Action denoland/setup-deno@v2 needs attention",
    "type": "unpinned_action",
    "file": "publish-jsr.yml",
    "action": "pin_sha",
    "rule_module": "workflow_audit",
    "severity": "medium"
  },
  {
    "reason": "Issue in scorecard-enforcer.yml",
    "type": "scorecard_publish_with_run_step",
    "file": "scorecard-enforcer.yml",
    "action": "split_scorecard_publish_job",
    "rule_module": "workflow_audit",
    "severity": "high"
  },
  {
    "reason": "Issue in instant-sync.yml",
    "type": "secret_action_without_presence_gate",
    "file": "instant-sync.yml",
    "action": "peter-evans/repository-dispatch",
    "rule_module": "workflow_audit",
    "severity": "high"
  },
  {
    "reason": "Shell execution -- validate input before passing to shell (1 occurrences, CWE-78)",
    "type": "js_exec_sync",
    "file": "/home/runner/work/affinescript/affinescript/packages/affinescript-cli/mod.js",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "high"
  },
  {
    "reason": "Shell execution -- validate input before passing to shell (2 occurrences, CWE-78)",
    "type": "js_exec_sync",
    "file": "/home/runner/work/affinescript/affinescript/packages/affine-vscode/mod.js",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "high"
  },
  {
    "reason": "Shell execution -- validate input before passing to shell (1 occurrences, CWE-78)",
    "type": "js_exec_sync",
    "file": "/home/runner/work/affinescript/affinescript/affinescript-vite/src/affine-plugin-improved.js",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "high"
  },
  {
    "reason": "expect() in hot path (32 occurrences, CWE-754)",
    "type": "expect_in_hot_path",
    "file": "/home/runner/work/affinescript/affinescript/affinescriptiser/src/codegen/wasm_gen.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "expect() in hot path (29 occurrences, CWE-754)",
    "type": "expect_in_hot_path",
    "file": "/home/runner/work/affinescript/affinescript/affinescriptiser/src/codegen/affine_gen.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "unsafe block -- requires SAFETY comment (2 occurrences, CWE-676)",
    "type": "unsafe_block",
    "file": "/home/runner/work/affinescript/affinescript/runtime/src/panic.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  },
  {
    "reason": "unsafe block -- requires SAFETY comment (1 occurrences, CWE-676)",
    "type": "unsafe_block",
    "file": "/home/runner/work/affinescript/affinescript/runtime/src/alloc.rs",
    "action": "flag",
    "rule_module": "code_safety",
    "severity": "medium"
  }
]

Powered by Hypatia Neurosymbolic CI/CD Intelligence

@hyperpolymath hyperpolymath marked this pull request as ready for review June 20, 2026 19:19
@hyperpolymath hyperpolymath merged commit 2efe0e3 into main Jun 20, 2026
16 checks passed
@hyperpolymath hyperpolymath deleted the claude/fix-deno-dup-constructors branch June 20, 2026 19:20
hyperpolymath added a commit that referenced this pull request Jun 21, 2026
…des #605) (#610)

Supersedes **#605** with the cosmetic defect from my `/review` resolved.
(I couldn't push the fix onto #605's branch — GitHub returns `403` on
`dependabot/*` branches — so this carries Dependabot's exact bump commit
plus the correction.)

### What's here
1. **Dependabot's commit** (`69f7fcc`) — `actions/checkout` v6.0.3 →
v7.0.0 (`df4cb1c…` → `9c091bb…`), unchanged.
2. **Comment normalization** (`0df4a5e`) — every `actions/checkout` line
now reads `# v7.0.0`. #605 left 14 lines tagged `# v4` (they'd been
mislabeled `# v4` in #604/#606, where that SHA was actually **v6.0.3**),
so the v7 SHA was carrying a `# v4` comment. Also adds the missing
comment on `publish-jsr.yml`'s bare line and refreshes the `ci.yml` pin
note.

`setup-node` / `upload-artifact` remain genuinely **v4** and are
untouched. **Comments only** beyond Dependabot's commit — no SHA or
logic change.

### Why it's safe
- SHA-pinned (`9c091bb…`), so compatible with the repo's "allowed
actions" policy (tag refs would `startup_fail`).
- v7's only breaking change (blocking fork-PR checkout for
`pull_request_target` / `workflow_run`) **does not apply** — the repo
uses neither trigger.
- YAML validated on all 14 workflows; the genuine-v4 actions verified
untouched.

### Action for you
Merge this and **close #605** (this is its corrected equivalent). If
you'd rather keep #605, close this instead and I'll land the comment fix
as a follow-up once #605 merges.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01Lz7pRcec2Z3tVtaAhvB3M8

---
_Generated by [Claude
Code](https://claude.ai/code/session_01Lz7pRcec2Z3tVtaAhvB3M8)_

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
hyperpolymath pushed a commit that referenced this pull request Jun 21, 2026
Mirror of the Deno-ESM fix (#606) for the JS backend, which shares the same
Some/None/Ok/Err runtime preamble. A program that declares `type Option` /
`type Result` (e.g. stdlib/prelude.affine) re-emitted those consts from the
TyEnum lowering, redeclaring them (SyntaxError under node). Skip the
preamble-provided constructors; user-defined enums are unaffected.

The C backend does NOT share this bug — it emits a tag-enum plus distinct
constructor functions (TAG_Some / Some()), with no Some/None preamble — so
#607's "JS/C" item is JS-only.

Adds a JS-path regression guard alongside the existing Deno one. Verified:
stdlib/prelude.affine -> JS has a single `const Some` and loads under node;
dune test 460 green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lz7pRcec2Z3tVtaAhvB3M8
hyperpolymath added a commit that referenced this pull request Jun 21, 2026
## What

Merges current `main` into `feat/solo-core-metatheory-proofs` and
resolves all conflicts, so that **#614 stops being `mergeable_state:
dirty`**. While #614 is dirty, GitHub cannot build the merge commit, so
its entire CI suite is suppressed (only `lint-workflows` runs). Merging
this PR into the feature branch un-blocks #614's CI.

## Why it was needed

#614 branched off an old `main` (merge-base 61 commits back) and
conflicts with the standalone-CI + codegen work that has since landed
(#602, #603, #604, #606, #609, #610, #611, #612, #613).

## Conflict resolutions (5 files)

| File(s) | Resolution |
|---|---|
| `governance.yml`, `scorecard.yml`, `scorecard-enforcer.yml`,
`hypatia-scan.yml` | Take `main`'s **standalone** versions. The branch
re-adopted the estate `standards` reusables that `main` deliberately
dropped (#603/#604) to stop run-creation `startup_failure`s. `main`'s
`hypatia-scan.yml` also restores the permissions Hypatia needs
(`security-events: write`, `pull-requests: write`, `secrets: inherit`)
and the `MPL-2.0` SPDX id the Palimpsest license doc mandates for
tooling. |
| `docs/PROOF-NEEDS.md` | Drop the branch's stale 103-line `.md`; keep
`main`'s canonical 359-line `.adoc` (#609). Also satisfies DOC-FORMAT. |
| `docs/history/MODULE-SYSTEM-PROGRESS` | Keep the branch's
`.md`→`.adoc` migration; **port** `main`'s additive #138
codegen-follow-up note + status-table row into the `.adoc` so `main`'s
work is preserved. |

`spark-theatre-gate.yml` and `mirror.yml` were identical to `main`.

## Verification (merged tree)

- `dune build` — clean
- `dune test` — **534/534 pass** (incl. `cross-module constructor
linking, Wasm (#138)`, `Wasm nested tuple patterns`, `Deno-ESM / JS no
duplicate Option/Result constructor`)
- wasm-runtime harness (`tools/run_codegen_wasm_tests.sh`) — all pass
- workflow scan — no `startup_failure` risk introduced

## How to use

Merge this into `feat/solo-core-metatheory-proofs`. #614 then becomes
mergeable and its full CI runs.

> Routed via this branch because the environment only permits pushes to
`claude/inspiring-newton-dg5wov`, not directly to the feature branch.

Un-blocks #614.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01Lz7pRcec2Z3tVtaAhvB3M8

---
_Generated by [Claude
Code](https://claude.ai/code/session_01Lz7pRcec2Z3tVtaAhvB3M8)_

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: hyperpolymath <paraordinate@yahoo.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants